package server;

import static org.junit.Assert.*;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.HashMap;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import server.communication.listeners.AuthenticationListener;


import client.Client;
import client.communication.ClientCommunicator;

public class ServerTest
{
	private static Server server;
	
	@BeforeClass
	public static void beforeTests() throws InstantiationException
	{
		server = new Server("config.xml");
		
		Thread thread = new Thread(new Runnable()
		{
			@Override
			public void run()
			{
				server.run();
			}
		});
		
		thread.start();
		
		while (!server.isReady())
		{
			try
			{
				Thread.sleep(10);
			}
			catch (InterruptedException e) {}
		}
	}
	@AfterClass
	public static void afterTests()
	{
		server.stop();
		
		while (server.isRunning())
		{
			try
			{
				Thread.sleep(10);
			}
			catch (InterruptedException e) {}
		}
	}
	@Test
	public void testRestart() throws InstantiationException
	{		
		server.restart();
		
		while (!server.isReady())
		{
			try
			{
				Thread.sleep(10);
			}
			catch (InterruptedException e) {}
		}
	}
}
